package com.lanou.tipsy.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;

import com.lanou.tipsy.R;
import com.lanou.tipsy.base.BaseActivity;
import com.lanou.tipsy.tools.custom.ThemePopupWindow;
import com.lanou.tipsy.tools.theme.ThemeMemory;

/**
 * 设置主题页面  弹出菜单,选择主题
 */


public class ThemeSettingActivity extends BaseActivity implements View.OnClickListener {
    public static final String TAG = "ThemeSettingActivity";
    private FrameLayout setTheme;
    private Button saveTheme;
    ThemePopupWindow menuWindow;  //自定义popupwindow

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //绑定布局前获取主题信息
        //ThemeMemory.onActivityCreateSetTheme(this);
        //去掉标题栏
        //this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_theme_setting);

        saveTheme = (Button) findViewById(R.id.saveTheme);
        saveTheme.setOnClickListener(this);

        setTheme = (FrameLayout) findViewById(R.id.setTheme);
        setTheme.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //实例化SelectPicPopupWindow
                menuWindow = new ThemePopupWindow(ThemeSettingActivity.this, itemsOnClick);
                //显示窗口
                menuWindow.showAtLocation(ThemeSettingActivity.this.findViewById(R.id.activityTest), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
            }
        });

    }

    //为弹出窗口实现监听类
    //默认为蓝色主题
    private View.OnClickListener itemsOnClick = new View.OnClickListener() {

        public void onClick(View v) {
            menuWindow.dismiss();
            switch (v.getId()) {
                default:
                case R.id.blue:
                    ThemeMemory.getInstance().changeToTheme(ThemeSettingActivity.this, 1);
                    break;
                case R.id.red:
                    ThemeMemory.getInstance().changeToTheme(ThemeSettingActivity.this, 2);
                    break;
                case R.id.orange:
                    ThemeMemory.getInstance().changeToTheme(ThemeSettingActivity.this, 3);
                    break;
                case R.id.yellow:
                    ThemeMemory.getInstance().changeToTheme(ThemeSettingActivity.this, 4);
                    break;
                case R.id.green:
                    ThemeMemory.getInstance().changeToTheme(ThemeSettingActivity.this, 5);
                    break;
                case R.id.black:
                    ThemeMemory.getInstance().changeToTheme(ThemeSettingActivity.this, 6);
                    break;
                case R.id.purple:
                    ThemeMemory.getInstance().changeToTheme(ThemeSettingActivity.this, 7);
                    break;
                case R.id.feng:
                    ThemeMemory.getInstance().changeToTheme(ThemeSettingActivity.this, 8);
                    break;
                //原定取消按钮
                /*case R.id.cancel:
                    Log.i("test", TAG + ">>>>>>>>>>>>");
                    Intent intent1 = new Intent(ThemeSettingActivity.this, MainActivity.class);
                    startActivity(intent1);
                    finish();*/
            }

        }

    };

    //跳转窗口时finish掉activity,返回时重启activity
    @Override
    public void onClick(View v) {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}
